From d1bcda0402cbc5b771a6defb3115c2fc21dfec69 Mon Sep 17 00:00:00 2001 From: alexmot Date: Fri, 18 Jul 2003 13:24:31 +0000 Subject: [PATCH] Fix "An attempt was made to access an unamed file past its end" issue in NG Topo. --- tpg.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tpg.c b/tpg.c index 208bf1658..777638e67 100644 --- a/tpg.c +++ b/tpg.c @@ -256,6 +256,7 @@ tpg_waypt_pr(const waypoint *wpt) char c; char *shortname; char *description; + static int out_count = 0; /* these unknown 4 are probably point properties (color, icon, etc..) */ unsigned char unknown4[] = { 0x78, 0x56, 0x34, 0x12 }; @@ -263,6 +264,9 @@ tpg_waypt_pr(const waypoint *wpt) /* these 2 appear to be constant across test files */ unsigned char unknown2[] = { 0x01, 0x80 }; + /* our personal waypoint counter */ + out_count++; + /* this output format pretty much requires a description * and a shortname */ @@ -336,7 +340,14 @@ tpg_waypt_pr(const waypoint *wpt) fwrite(description, 1, c, tpg_file_out); /* and finally 2 unknown bytes */ - fwrite(unknown2, 1, 2, tpg_file_out); + + if (out_count == waypt_count()) { + /* last point gets 0x0000 instead of 0x0180 */ + memset(tbuf, '\0', sizeof(tbuf)); + fwrite(tbuf, 1, 2, tpg_file_out); + } else { + fwrite(unknown2, 1, 2, tpg_file_out); + } xfree(shortname); xfree(description); -- 2.30.2